import os
import yaml
from logger.log_config import logger

# 获取当前环境，默认是 'development'
current_env = os.getenv("ENV", "development")

# 读取 config.yaml
with open("config.yaml", "r") as file:
    configs = yaml.safe_load(file)

# 确保 ENV 合法
if current_env not in configs:
    raise ValueError(f"未找到 '{current_env}' 配置，请检查 config.yaml")

# 解析环境变量
config = configs[current_env]

# 赋值变量（便于代码引用）
zhipu_config = config["zhipu"]
APIKEY = zhipu_config["APIKEY"]
MODEL_URI = zhipu_config["URL"]
MODEL = zhipu_config["MODEL"]
TEMPERATURE = zhipu_config["TEMPERATURE"]
TOP_P = zhipu_config["TOP_P"]

# 显示当前环境（可选）
logger.info(f"[INFO] 当前环境: {current_env}, MODEL_URI: {MODEL_URI}")

# 解析 MySQL 配置（嵌套结构）
mysql_config = config["mysql"]
MYSQL_HOST = mysql_config["host"]
MYSQL_PORT = mysql_config["port"]
MYSQL_USERNAME = mysql_config["username"]
MYSQL_PASSWORD = mysql_config["password"]
MYSQL_DATABASE = mysql_config["database"]

oss_config = config["oss"]
OSS_ACCESS_KEY_ID = oss_config["access_key_id"]
OSS_ACCESS_KEY_SECRET = oss_config["access_key_secret"]
OSS_ENDPOINT = oss_config["endpoint"]
OSS_BUCKET = oss_config["bucket"]
OOS_REGION = oss_config["region"]

tts_config = config["tts"]
TTS_APPID = tts_config["appid"]
TTS_ACCESS_TOKEN = tts_config["access_token"]
TTS_CLUSTER = tts_config["cluster"]
TTS_VOICE_TYPE = tts_config["voice_type"]
TTS_API_URL = tts_config["api_url"]


asr_config = config["asr"]
ASR_APPID = asr_config["appid"]
ASR_TOKEN = asr_config["token"]
ASR_CLUSTER = asr_config["cluster"]
ASR_AUDIO_FORMAT = asr_config["audio_format"]